package chapterSystem.client.interfaceDrawing.activities;

import chapterSystem.client.ChapterSystemService;
import chapterSystem.client.callbacks.WriteSimpleEntityCallback;
import chapterSystem.client.model.entitiesInt.Brother;
import chapterSystem.client.model.entitiesInt.Order;
import chapterSystem.client.model.enums.ActivityType;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.StackLayoutPanel;

/**
 * User: Hasp
 * Date: 22.04.12
 * Time: 18:04
 */
public class EditOrderExecutionActivity extends WriteOrderExecutionActivity {
    protected EditOrderExecutionActivity(final Brother brother, final ActivityType type, Order order, Activity callback) {
        super(brother, type, order, callback);
        submitArea.setText(order.getExecutionReport());
    }

    @Override
    protected ClickHandler createClickHandler(final StackLayoutPanel workArea) {
        return new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                if (submitArea.getText().trim().length() > 0) {
                    order.setText(submitArea.getText());
                    ChapterSystemService.App.getInstance().editExecutionReport(order,
                            new WriteSimpleEntityCallback(workArea, callback));
                } else {
                    Window.alert("Execution report text must not be empty");
                }
            }
        };
    }
}
